package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cnzz.site1255174697.Const;
import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.model.BaseEntity;
import com.cqyanyu.yanyu.model.EventEntity;
import com.cqyanyu.yanyu.view.XBaseViewHolder;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * 文字宫格
 */
public class KindsGridAdapter extends BaseAdapter {

    private Context context;
    private int select = -1;
    private List<BaseEntity> list;
    View.OnClickListener OnClickListener;

    public KindsGridAdapter(Context context, List<BaseEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public BaseEntity getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_text_noimg, null);
        }
        TextView xyTitle = XBaseViewHolder.get(convertView, R.id.xy_title);

        BaseEntity kindsEntity = list.get(position);
        xyTitle.setText(kindsEntity.getName());

        if (select == position) {
            xyTitle.setTextColor(context.getResources().getColor(R.color.colorAccent1));
        } else {
            xyTitle.setTextColor(context.getResources().getColor(R.color.text_black));
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventEntity e = new EventEntity();
                e.type = Const.JUMP_CLICK;
                e.id = position;
                EventBus.getDefault().post(e);
            }
        });
        return convertView;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
    }


}
